package xuhaijia.lanou3g.autohome.forum.hotinvitation;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.SimpleDateFormat;

import xuhaijia.lanou3g.autohome.R;

/**
 * Created by 7 on 16/8/17.
 */
public class HotInvitationAdapter extends BaseAdapter {
    HotInvitationBean bean;
    Context context;

    public HotInvitationAdapter(Context context) {
        this.context = context;
    }

    public void setBean(HotInvitationBean bean) {
        this.bean = bean;
    }

    @Override
    public int getCount() {
        if (bean.getResult().getList() == null) {
            return 0;
        }
        return bean.getResult().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_hotinvitation, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        HotInvitationBean.ResultBean.ListBean listBean =
                bean.getResult().getList().get(position);
        viewHolder.titleTv.setText(listBean.getTitle());
        viewHolder.historyTv.setText(listBean.getReplycounts() + "回帖");
        viewHolder.bbsTv.setText(listBean.getBbsname());
        String date = listBean.getPostdate();
        viewHolder.dateTv.setText(date.substring(6, 16));
        if (listBean.getIspictopic() !=1 ) {
            viewHolder.havepicIv.setVisibility(View.INVISIBLE);
        } else {
            viewHolder.havepicIv.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    private class ViewHolder {
        TextView titleTv;
        TextView bbsTv;
        TextView dateTv;
        ImageView havepicIv;
        TextView historyTv;

        public ViewHolder(View view) {
            titleTv = (TextView) view.findViewById(R.id.hotinvitation_title);
            bbsTv = (TextView) view.findViewById(R.id.hotinvitation_bbsname);
            dateTv = (TextView) view.findViewById(R.id.hotinvitation_date);
            havepicIv = (ImageView) view.findViewById(R.id.hotinvitation_havepic);
            historyTv = (TextView) view.findViewById(R.id.hotinvitation_history);
        }
    }
}
